<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">

   <title>修改协议</title>
   
   <link rel="stylesheet" href="__PUBLIC__/Css/Admin/common.css">
   <link rel="stylesheet" href="__PUBLIC__/Css/Admin/main.css">
   <style type="text/css">
	  .editor{
		  width:60%;
	  	  height:300px;
  		  margin-bottom:50px;
	  }
   </style>
   
   <script type="text/javascript" src="__PUBLIC__/Js/Admin/jquery.min.js"></script>
   <script type="text/javascript" charset="utf-8" src="__PUBLIC__/ueditor/ueditor.config.js"></script>
   <script type="text/javascript" charset="utf-8" src="__PUBLIC__/ueditor/ueditor.all.min.js"> </script>
   <script type="text/javascript" charset="utf-8" src="__PUBLIC__/ueditor/lang/zh-cn/zh-cn.js"></script>
   
   <script type="text/javascript">
       $(function(){
    	   // 初始化编辑器
    	   UE.getEditor("protocol");
    	   
    	   // 提交前check
    	   checkBeforeSubmit();
       });
       
       // 提交前check
       function checkBeforeSubmit(){
    	   $("#save_button").click(function(){
    		   var protocolId = $("input[name='protocol_id']").val();
    		   // 协议标题
    		   var protocolTitle = $("input[name='protocol_title']").val();
    		   // 协议简介
    		   var contentTxt = UE.getEditor("protocol").getContentTxt();// 获得纯文本
    		   var about = "";// 游记摘要(取前300个字)
	       	   if($.trim(contentTxt) != ""){
	       			if(contentTxt.length > 300){
	       				about = contentTxt.substring(0,300);
	       			} else {
	       				about = contentTxt;
	       			}
	       	   }
	       	   $("input[name='protocol_about']").val(about);
    		   // 协议内容
    		   var protocol = UE.getEditor("protocol").hasContents()
    		   
    		   // 输入check 
    		   if($.trim(protocolTitle) == ""){
    			   alert("请输入协议标题！");
    			   return false;
    		   }
    		   if($.trim(protocol) == ""){
    			   alert("请输入协议内容！");
    			   return false;
    		   }
    		   
    		   if($.trim(protocolId) == ""){
    			   $.ajax({
    	    			  url:"__URL__/hasProtocolExisted",
    	    			  type:"POST",
    					  async: false,
    					  data: "protocol_title=" + $.trim(protocolTitle),
    					  dataType: "json",
    					  success:function(data) {
    						  	if(data.status == 200){
    	  							//已经存在
    	  							alert(data.message);
    	  							$(this).focus();
    	  						} else {
    	  							$("#protocol_form").submit(); 
    	  						}
    					  },
    					  error:function(){
    					    	
    					  }
    	    		   });
    		   } else {
    			   $.ajax({
 	    			  url:"__URL__/hasProtocolExisted",
 	    			  type:"POST",
 					  async: false,
 					  data: "id=" + $.trim(protocolId) + "&protocol_title=" + $.trim(protocolTitle),
 					  dataType: "json",
 					  success:function(data) {
 						  	if(data.status == 200){
 	  							//已经存在
 	  							alert(data.message);
 	  							$(this).focus();
 	  						} else {
 	  							$("#protocol_form").submit(); 
 	  						}
 					  },
 					  error:function(){
 					    	
 					  }
 	    		   }); 
    		   }
    	   });
       }
   </script>
</head>
<body>
<div id="forms" class="mt10">
       <div class="box">
          <div class="box_border">
            <div class="box_top">
            	<b class="pl15">{$title}</b>
            	<a class="ext_btn" onclick="location.href='javascript:history.go(-1)'" style="float:right;margin-right:10px;margin-top:5px;">返回</a>
            </div>
            <div class="box_center">
              <form action="{:U('Other/saveProtocol')}" class="jqtransform" id="protocol_form" method="post" enctype="multipart/form-data">
                <input type="hidden" name="protocol_id" value="{$protocol.id}">
                <input type="hidden" name="protocol_about" value="{$protocol.about}">
               <table class="form_table pt15 pb15" style="width:100%">
                 <tr>
                  <td class="td_right"><label style="color:red;">*</label>协议标题：</td>
                  <td class=""> 
                    <input type="text" name="protocol_title" class="input-text lh30" size="40" value="{$protocol.protocol_title}">
                  </td>
                </tr>
                <tr>
                  <td class="td_right" style="vertical-align:top;"><label style="color:red;">*</label>协议内容：</td>
                  <td class=""> 
                      <script id="protocol" class="editor" type="text/plain" name="protocol">
					  		{$protocol.protocol}
					  </script> 
                  </td>
                </tr>
                 <tr>
                   <td class="td_right">&nbsp;</td>
                   <td class="">
                     <input type="button" name="save_button" id="save_button" class="btn btn82 btn_save2" value="保存"> 
                    <input type="reset" name="reset_button" class="btn btn82 btn_res" value="重置">
                   </td>
                 </tr>
               </table>
               </form>
            </div>
          </div>
        </div>
     </div>
</body>
</html>